//
//  NSArray+LILExtension.m
//  LILTools
//
//  Created by xl on 2023/11/4.
//

#import "NSArray+LILExtension.h"

@implementation NSArray (LILExtension)

- (NSArray *)lil_randomArray {
    if (self.count == 0) return self;

    NSMutableArray *array = [NSMutableArray arrayWithArray:self];
    for (NSUInteger i = self.count - 1; i > 0; i--) {
        [array exchangeObjectAtIndex:i withObjectAtIndex:arc4random_uniform((uint32_t)(i + 1))];
    }

    return [array copy];
}

- (nullable id)lil_randomObject {
    if (self.count == 0) return nil;
    return self[arc4random_uniform((u_int32_t)self.count)];
}

@end
